import time

import allure
from selenium.webdriver.common.by import By

from Base.BackBase.baseBack import BasePage, BaseHandle


# 后台首页页面的对象库层
class HomePage(BasePage):
    def __init__(self):
        super().__init__()
        # 用户名
        self.my_username = By.CSS_SELECTOR, "[class='user_info'] span"
        # 信息管理
        self.info_manage = By.CSS_SELECTOR, ".fa-shopping-basket"
        # 内容审核
        self.content_audit = By.XPATH, "//ul[@class='current3']/li[3]/a"

    #         定位用户名
    def find_my_username(self):
        return self.get_element(self.my_username)

    #       定位信息管理
    def find_info_manage(self):
        return self.get_element(self.info_manage)

    #       定位内容审核
    def find_content_audit(self):
        return self.get_element(self.content_audit)


# 后台首页页面的操作层
class HomeHandle(BaseHandle):
    def __init__(self):
        self.home_page = HomePage()

    #     获取我的账户名
    @allure.step(title="获取我的账户名")
    def get_my_username(self):
        return self.home_page.find_my_username().text

    #     点击信息管理
    @allure.step(title="点击信息管理")
    def click_info_manage(self):
        self.home_page.find_info_manage().click()

    #     点击内容审核
    @allure.step(title="点击内容审核")
    def click_content_audit(self):
        self.home_page.find_content_audit().click()


# 后台首页页面的业务层
class HomeProxy:
    def __init__(self):
        self.home_handle = HomeHandle()

    # 获取到我的账户名
    def my_username(self):
        return self.home_handle.get_my_username()

    # 选择内容审核页面
    def go_content_audit(self):
        self.home_handle.click_info_manage()
        time.sleep(1)
        self.home_handle.click_content_audit()
